package com.example.latte_core.net;

import com.example.latte_core.app.ConfigType;
import com.example.latte_core.app.Latte;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RestCreator {

    private static final class RetrofitHolder{

        public  static  RestService getRestService(){
            return  RestServiceHolder.REST_SERVER;
        }

        private static final String BASE_URL = (String) Latte.getConfiguratitions().get(ConfigType.API_HOST);
        private static final Retrofit RETROFIT_CLIENT = new Retrofit
                .Builder()
                .baseUrl(BASE_URL)
                .client(OkHttpHolder.OK_HTTP_CLIENT)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    private static  final class OkHttpHolder{
        private static  final  int TIME_OUT = 60;
        private static  final OkHttpClient OK_HTTP_CLIENT = new OkHttpClient.Builder()
        .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
        .build();

    }

    private static  final  class RestServiceHolder{
        private static  final  RestService REST_SERVER = RetrofitHolder.RETROFIT_CLIENT.create(RestService.class);

    }
}
